﻿@model HelloMinasan.Web.Song.ViewModels.TestListViewModel

@{
    ViewBag.Title = "TestList";

    bool isOwner = Request.IsAuthenticated &&
               (int.Parse(User.Identity.Name) == Model.Owner
               || User.Identity.Name.ToLower() == "admin") ? true : false; 
}
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.msgbox.min.js")"></script>
<link href="@Url.Content("~/Content/jquery.msgbox.css")" rel="stylesheet" />
<script>
    function deleteTest(id, type) {
        $.msgbox("Are you sure that you want to permanently delete the selected element?", {
            type: "info",
            buttons: [
              { type: "submit", value: "Yes" },
              { type: "submit", value: "No" },
            ]
        }, function (result) {
            if (result == "Yes") {
                $.ajax(
                {
                    type: "POST",
                    url: "/Song/DeleteTest",
                    data: { testId: id, typeAction: type },
                    success: function (result) {
                        $.msgbox(result.Message, { type: "info" });
                        if (result.Result) {
                            location.reload();
                        }
                    }
                });
            }
        });

    }
</script>

<body style="height: auto">
    <div class="contentSectionInside">
        <div style="margin-top: 10px;">
            <div class="contentSectionInside" style="display: table; width: 97%">
                Quiz test
            <div align="right" style="float: right">
                @if (isOwner)
                { 
                    <a href="/Song/EditTest/@Model.SongId">
                        <img src="/Content/Images/addsmall.png" />
                    </a>
                }
            </div>
            </div>
            <div class="testListContent">
                @if (Model.Quizs.Any())
                {
                    foreach (var item in Model.Quizs)
                    {
                    <a href="/Song/DoTest/@item.SongId?testId=@item.Id">
                        <div align="center" class="testItemList">
                            @item.PostedDate
                            <br />
                            0 test time(s)
                    @if (isOwner)
                    {
                        <a href="/Song/EditTest/@Model.SongId/@item.Id">
                            <img src="/Content/Images/allowEdit.png" /></a>
                        <a onclick="deleteTest(@item.Id, false)">
                            <img src="/Content/Images/error.png" width="20" /></a>
                    }
                        </div>
                    </a>
                    }
                }
                else
                {
                    <div style="padding: 10px;">There is no quiz test yet.</div>
                }
            </div>
        </div>

        <div>
            <div class="contentSectionInside" style="display: table; width: 97%">
                Blank Test
                <div align="right" style="float: right">
                    @if (isOwner)
                    { 
                        <a href="/Song/EditBlank/@Model.SongId">
                            <img src="@Url.Content("/Content/Images/addsmall.png")" />
                        </a>
                    }
                </div>
            </div>

            <div class="testListContent">
                @if (Model.Blanks.Any())
                {
                    foreach (var item in Model.Blanks)
                    {
                    <div align="center" class="testItemList selectItemForExpand">
                        <div class="itemHidden">
                            <ul>
                                <li><a href="/Song/DoBlankTest/@item.Song.Id?mode=Easy&testId=@item.Id" style="display:block">Easy</a></li>
                                <li><a href="/Song/DoBlankTest/@item.Song.Id?mode=Hard&testId=@item.Id" style="display:block">Hard</a></li>
                            </ul>
                        </div>
                        <div>
                            @item.PostedDate
                            <br />
                            0 test time(s)
                            <br />
                            @if (isOwner)
                            {
                                <a href="/Song/EditBlank/@Model.SongId/@item.Id">
                                    <img src="@Url.Content("/Content/Images/allowEdit.png")">
                                </a>
                                <a onclick="deleteTest(@item.Id, true)">
                                    <img src="@Url.Content("/Content/Images/error.png")" width="20" /></a>
                            }
                        </div>
                    </div>
                
                    }
                }
                else
                {
                    <div style="padding: 10px;">There is no blank test yet.</div>
                }
            </div>
        </div>
    </div>
    <div class="modalPopup"></div>
</body>
